/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecom.beans.customer;

import ecom.beans.account.*;
import ecom.beans.address.*;


import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;


@NamedQueries({
    
    @NamedQuery(name = "findAllCustomers",
    query = "SELECT customer FROM CustomerEntity customer"),
            
    @NamedQuery(name = "findCustomerById",
    query = "SELECT customer FROM CustomerEntity customer WHERE customer.id = :id"),
            
    @NamedQuery(name = "findCustomerByPassword",
    query = "SELECT customer FROM CustomerEntity customer WHERE customer.password = :password"),
            
    @NamedQuery(name = "findCustomerByEmail",
    query = "SELECT customer FROM CustomerEntity customer WHERE customer.email = :email"),
            
    @NamedQuery(name = "identifyClient",
    query = "SELECT customer FROM CustomerEntity customer WHERE customer.email = :email AND customer.password = :password")
            
})
@Entity
public class CustomerEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String firstName;
    private String lastName;
    private String tel;
    private String email;
    private String password;
    private int smilesNumber;
    

    @OneToOne(cascade ={CascadeType.ALL})
    private AddressEntity customerAddress;
    
    @OneToOne(cascade ={CascadeType.ALL})
    private AccountEntity customerAccount;
             
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getId() {
        return id;
    }
    
    public AddressEntity getCustomerAddress() {
        return customerAddress;
    }

    public void setCustomerAddress(AddressEntity customerAddress) {
        this.customerAddress = customerAddress;
    }

 
    public AccountEntity getCustomerAccount() {
        return customerAccount;
    }

    public void setCustomerAccount(AccountEntity customerAccount) {
        this.customerAccount = customerAccount;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstname() {
        return firstName;
    }

    public void setFirstname(String firstname) {
        this.firstName = firstname;
    }

    public String getLastname() {
        return lastName;
    }

    public void setLastname(String lastname) {
        this.lastName = lastname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public int getSmilesNumber() {
        return smilesNumber;
    }

    public void setSmilesNumber(int smilesNumber) {
        this.smilesNumber = smilesNumber;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CustomerEntity)) {
            return false;
        }
        CustomerEntity other = (CustomerEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        
        return "ejb.customer.CustomerEntity[id=" + id + "]";
        
    }

}